VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "PPLB Lib Example"
   ClientHeight    =   1485
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   3885
   LinkTopic       =   "Form1"
   ScaleHeight     =   1485
   ScaleWidth      =   3885
   StartUpPosition =   2  'CenterScreen
   Begin VB.CommandButton Command1 
      Caption         =   "Print Label"
      Height          =   500
      Left            =   900
      TabIndex        =   0
      Top             =   400
      Width           =   2100
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
    Private Type SECURITY_ATTRIBUTES
        nLength As Long
        lpSecurityDescriptor As Long
        bInheritHandle As Long
    End Type

    Private Declare Function CreateDirectory Lib "kernel32" Alias "CreateDirectoryA" _
            (ByVal lpPathName As String, lpSecurityAttributes As SECURITY_ATTRIBUTES) As Long
            
    Const IMAGE_BITMAP = 0
    Const LR_LOADFROMFILE = &H10
    Private Declare Function LoadImage Lib "user32" Alias "LoadImageA" (ByVal hInst As Long, _
            ByVal lpsz As String, ByVal un1 As Long, ByVal n1 As Long, ByVal n2 As Long, _
            ByVal un2 As Long) As Long
    Private Declare Function DeleteObject Lib "Gdi32" (ByVal ho As Long) As Long
    Const szSavePath As String = "C:\Argox"
    Const szSaveFile As String = "C:\Argox\PPLB_Example.Prn"
    Const sznop1 As String = "nop_front" + vbCrLf
    Const sznop2 As String = "nop_middle" + vbCrLf
    Private Declare Function B_Bar2d_Maxi Lib "WINPPLB.DLL" (ByVal x As Long, ByVal y As Long, _
            ByVal cl As Long, ByVal cc As Long, ByVal pc As Long, ByVal data As String) As Long
    Private Declare Function B_Bar2d_PDF417 Lib "WINPPLB.DLL" (ByVal x As Long, ByVal y As Long, _
            ByVal w As Long, ByVal v As Long, ByVal s As Long, ByVal c As Long, ByVal px As Long, _
            ByVal py As Long, ByVal r As Long, ByVal l As Long, ByVal t As Long, ByVal o As Long, _
            ByVal data As String) As Long
    Private Declare Function B_Bar2d_PDF417_N Lib "WINPPLB.DLL" (ByVal x As Long, ByVal y As Long, _
            ByVal w As Long, ByVal h As Long, ByVal pParameter As String, ByVal data As String) As Long
    Private Declare Function B_Bar2d_DataMatrix Lib "WINPPLB.DLL" (ByVal x As Integer, ByVal y As Integer, _
            ByVal r As Integer, ByVal l As Integer, ByVal h As Integer, ByVal v As Integer, _
            ByVal data As String) As Integer
    Private Declare Sub B_ClosePrn Lib "WINPPLB.DLL" ()
    Private Declare Function B_CreatePrn Lib "WINPPLB.DLL" (ByVal selection As Long, _
            ByVal filename As String) As Long
    Private Declare Function B_Del_Form Lib "WINPPLB.DLL" (ByVal formname As String) As Long
    Private Declare Function B_Del_Pcx Lib "WINPPLB.DLL" (ByVal pcxname As String) As Long
    Private Declare Function B_Draw_Box Lib "WINPPLB.DLL" (ByVal x As Long, ByVal y As Long, _
            ByVal thickness As Long, ByVal hor_dots As Long, ByVal ver_dots As Long) As Long
    Private Declare Function B_Draw_Line Lib "WINPPLB.DLL" (ByVal mode As Byte, ByVal x As Long, _
            ByVal y As Long, ByVal hor_dots As Long, ByVal ver_dots As Long) As Long
    Private Declare Function B_Error_Reporting Lib "WINPPLB.DLL" (ByVal options As Byte) As Long
    Private Declare Function B_Get_DLL_Version Lib "WINPPLB.DLL" (ByVal nShowMessage As Long) As Long ' return point address.
    Private Declare Function B_Get_DLL_VersionA Lib "WINPPLB.DLL" (ByVal nShowMessage As Long) As Long
    Private Declare Function B_Get_Graphic_ColorBMP Lib "WINPPLB.DLL" (ByVal x As Long, _
            ByVal y As Long, ByVal filename As String) As Long
    Private Declare Function B_Get_Graphic_ColorBMPEx Lib "WINPPLB.DLL" (ByVal x As Long, _
            ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, _
            ByVal rotate As Long, ByVal id_name As String, ByVal filename As String) As Long
    Private Declare Function B_Get_Graphic_ColorBMP_HBitmap Lib "WINPPLB.DLL" (ByVal x As Long, _
            ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, _
            ByVal rotate As Long, ByVal id_name As String, ByVal hbm As Long) As Long
    Private Declare Function B_Get_Pcx Lib "WINPPLB.DLL" (ByVal x As Long, ByVal y As Long, _
            ByVal filename As String) As Long
    Private Declare Function B_Initial_Setting Lib "WINPPLB.DLL" (ByVal TType As Long, _
            ByVal Source As String) As Long
    Private Declare Function B_WriteData Lib "WINPPLB.DLL" (ByVal IsImmediate As Long, _
            ByVal pbuf As String, ByVal length As Long) As Long
    Private Declare Function B_ReadData Lib "WINPPLB.DLL" (ByVal pbuf As String, _
            ByVal length As Long, ByVal dwTimeoutms As Long) As Long
    Private Declare Function B_Load_Pcx Lib "WINPPLB.DLL" (ByVal x As Long, ByVal y As Long, _
            ByVal pcxname As String) As Long
    Private Declare Function B_Open_ChineseFont Lib "WINPPLB.DLL" (ByVal path As String) As Long
    Private Declare Function B_Print_Form Lib "WINPPLB.DLL" (ByVal labset As Long, _
            ByVal copies As Long, ByVal form_out As String, ByVal var As String) As Long
    Private Declare Function B_Print_MCopy Lib "WINPPLB.DLL" (ByVal labset As Long, _
            ByVal copies As Long) As Long
    Private Declare Function B_Print_Out Lib "WINPPLB.DLL" (ByVal labset As Long) As Long
    Private Declare Function B_Prn_Barcode Lib "WINPPLB.DLL" (ByVal x As Long, ByVal y As Long, _
            ByVal ori As Long, ByVal TType As String, ByVal narrow As Long, ByVal width As Long, _
            ByVal height As Long, ByVal human As Byte, ByVal data As String) As Long
    Private Declare Sub B_Prn_Configuration Lib "WINPPLB.DLL" ()
    Private Declare Function B_Prn_Text Lib "WINPPLB.DLL" (ByVal x As Long, ByVal y As Long, _
            ByVal ori As Long, ByVal font As Long, ByVal hor_factor As Long, _
            ByVal ver_factor As Long, ByVal mode As Byte, ByVal data As String) As Long
    Private Declare Function B_Prn_Text_Chinese Lib "WINPPLB.DLL" (ByVal x As Long, ByVal y As Long, _
            ByVal fonttype As Long, ByVal id_name As String, ByVal data As String) As Long
    Private Declare Function B_Prn_Text_TrueType Lib "WINPPLB.DLL" (ByVal x As Long, ByVal y As Long, _
            ByVal FSize As Long, ByVal FType As String, ByVal Fspin As Long, ByVal FWeight As Long, _
            ByVal FItalic As Long, ByVal FUnline As Long, ByVal FStrikeOut As Long, _
            ByVal id_name As String, ByVal data As String) As Long
    Private Declare Function B_Prn_Text_TrueType_W Lib "WINPPLB.DLL" (ByVal x As Long, _
            ByVal y As Long, ByVal FHeight As Long, ByVal FWidth As Long, ByVal FType As String, _
            ByVal Fspin As Long, ByVal FWeight As Long, ByVal FItalic As Long, ByVal FUnline As Long, _
            ByVal FStrikeOut As Long, ByVal id_name As String, ByVal data As String) As Long
    Private Declare Function B_Select_Option Lib "WINPPLB.DLL" (ByVal object_Renamed As Long) As Long
    Private Declare Function B_Select_Option2 Lib "WINPPLB.DLL" (ByVal object_Renamed As Long, _
            ByVal p As Long) As Long
    Private Declare Function B_Select_Symbol Lib "WINPPLB.DLL" (ByVal num_bit As Long, _
            ByVal symbol As Long, ByVal country As Long) As Long
    Private Declare Function B_Select_Symbol2 Lib "WINPPLB.DLL" (ByVal num_bit As Long, _
            ByVal symbol As String, ByVal country As Long) As Long
    Private Declare Function B_Set_Backfeed Lib "WINPPLB.DLL" (ByVal options As Byte) As Long
    Private Declare Function B_Set_Backfeed_Offset Lib "WINPPLB.DLL" (ByVal offset As Long) As Long
    Private Declare Function B_Set_CutPeel_Offset Lib "WINPPLB.DLL" (ByVal offset As Long) As Long
    Private Declare Function B_Set_BMPSave Lib "WINPPLB.DLL" (ByVal nSave As Long, _
            ByVal pstrBMPFName As String) As Long
    Private Declare Function B_Set_Darkness Lib "WINPPLB.DLL" (ByVal darkness As Long) As Long
    Private Declare Function B_Set_DebugDialog Lib "WINPPLB.DLL" (ByVal nEnable As Long) As Long
    Private Declare Function B_Set_Direction Lib "WINPPLB.DLL" (ByVal direction As Byte) As Long
    Private Declare Function B_Set_Form Lib "WINPPLB.DLL" (ByVal formfile As String) As Long
    Private Declare Function B_Set_Labgap Lib "WINPPLB.DLL" (ByVal lablength As Long, _
            ByVal gaplength As Long) As Long
    Private Declare Function B_Set_Labwidth Lib "WINPPLB.DLL" (ByVal labwidth As Long) As Long
    Private Declare Function B_Set_Originpoint Lib "WINPPLB.DLL" (ByVal hor As Long, _
            ByVal ver As Long) As Long
    Private Declare Function B_Set_Prncomport Lib "WINPPLB.DLL" (ByVal baud As Long, _
            ByVal parity As Byte, ByVal data As Long, ByVal stopp As Long) As Long
    Private Declare Function B_Set_Prncomport_PC Lib "WINPPLB.DLL" (ByVal nBaudRate As Long, _
            ByVal nByteSize As Long, ByVal nParity As Long, ByVal nStopBits As Long, _
            ByVal nDsr As Long, ByVal nCts As Long, ByVal nXonXoff As Long) As Long
    Private Declare Function B_Set_Speed Lib "WINPPLB.DLL" (ByVal speed As Long) As Long
    Private Declare Function B_Set_ProcessDlg Lib "WINPPLB.DLL" (ByVal nShow As Long) As Long
    Private Declare Function B_Set_ErrorDlg Lib "WINPPLB.DLL" (ByVal nShow As Long) As Long
    Private Declare Function B_GetUSBBufferLen Lib "WINPPLB.DLL" () As Long
    Private Declare Function B_EnumUSB Lib "WINPPLB.DLL" (ByVal buf As String) As Long
    Private Declare Function B_CreateUSBPort Lib "WINPPLB.DLL" (ByVal nPort As Long) As Long
    Private Declare Function B_ResetPrinter Lib "WINPPLB.DLL" () As Long
    Private Declare Function B_GetPrinterResponse Lib "WINPPLB.DLL" (ByVal pbuf As String, _
            ByVal nMax As Long) As Long
    Private Declare Function B_TFeedMode Lib "WINPPLB.DLL" (ByVal nMode As Long) As Long
    Private Declare Function B_TFeedTest Lib "WINPPLB.DLL" () As Long
    Private Declare Function B_CreatePort Lib "WINPPLB.DLL" (ByVal nPortType As Long, _
            ByVal nPort As Long, ByVal filename As String) As Long
    Private Declare Function B_Execute_Form Lib "WINPPLB.DLL" (ByVal form_out As String, _
            ByVal var As String) As Long
    Private Declare Function B_Bar2d_QR Lib "WINPPLB.DLL" (ByVal x As Long, ByVal y As Long, _
            ByVal model As Long, ByVal scl As Long, ByVal err As Byte, ByVal dinput As Byte, _
            ByVal c As Long, ByVal d As Long, ByVal p As Long, ByVal data As String) As Long
    Private Declare Function B_GetNetPrinterBufferLen Lib "WINPPLB.DLL" () As Long
    Private Declare Function B_EnumNetPrinter Lib "WINPPLB.DLL" (ByVal buf As String) As Long
    Private Declare Function B_CreateNetPort Lib "WINPPLB.DLL" (ByVal nPort As Long) As Long
    'data is buffer address, so can use "ByVal data As Integer".
    Private Declare Function B_Prn_Text_TrueType_Uni Lib "WINPPLB.DLL" (ByVal x As Long, _
            ByVal y As Long, ByVal FSize As Long, ByVal FType As String, ByVal Fspin As Long, _
            ByVal FWeight As Long, ByVal FItalic As Long, ByVal FUnline As Long, _
            ByVal FStrikeOut As Long, ByVal id_name As String, ByRef data As Byte, _
            ByVal format As Long) As Long
    'data is buffer address, so can use "ByVal data As Integer".
    Private Declare Function B_Prn_Text_TrueType_UniB Lib "WINPPLB.DLL" (ByVal x As Long, _
            ByVal y As Long, ByVal FSize As Long, ByVal FType As String, ByVal Fspin As Long, _
            ByVal FWeight As Long, ByVal FItalic As Long, ByVal FUnline As Long, _
            ByVal FStrikeOut As Long, ByVal id_name As String, ByRef data As Byte, _
            ByVal format As Long) As Long
    Private Declare Function B_GetUSBDeviceInfo Lib "WINPPLB.DLL" (ByVal nPort As Long, _
            ByVal pDeviceName As String, ByRef pDeviceNameLen As Long, ByVal pDevicePath As String, _
            ByRef pDevicePathLen As Long) As Long
    Private Declare Function B_Set_EncryptionKey Lib "WINPPLB.DLL" (ByVal encryptionKey As String) As Long
    Private Declare Function B_Check_EncryptionKey Lib "WINPPLB.DLL" (ByVal decodeKey As String, _
            ByVal encryptionKey As String, ByVal dwTimeoutms As Long) As Long
    Private Declare Function B_Set_CommTimeout Lib "WINPPLB.DLL" (ByVal ReadTotalTimeoutConstant As Long, _
            ByVal WriteTotalTimeoutConstant As Long) As Long
    Private Declare Function B_Get_CommTimeout Lib "WINPPLB.DLL" (ByRef ReadTotalTimeoutConstant As Long, _
            ByRef WriteTotalTimeoutConstant As Long) As Long
    Private Declare Function B_Set_LabelForSmartPrint Lib "WINPPLB.DLL" (ByVal lablength As Long, _
            ByVal gaplength As Long) As Long

Private Sub Command1_Click()
        'Test code start
        ' open port.
        Dim nLen As Long
        Dim ret As Long
        Dim sw As Long
        Dim nVersion, nMainVersion, nSubVersion As Long
        Dim pbuf As String
        Dim strmsg As String
        pbuf = Space(128)
        ver = Space(128)

        ' dll version.
        nVersion = B_Get_DLL_VersionA(0)
        nMainVersion = Int(nVersion / 100)
        nSubVersion = nVersion Mod 100
        
        ' search port.
        nLen = B_GetUSBBufferLen() + 1
        strmsg = "DLL Ver: " + Str(nMainVersion) + "." + Str(nSubVersion) + vbCrLf  'only sample coding, not smart.
        If nLen > 1 Then
            Dim buf1 As String
            Dim buf2 As String
            Dim len1 As Long
            Dim len2 As Long
            len1 = 128
            len2 = 128
            buf1 = Space(len1)
            buf2 = Space(len2)
            Call B_EnumUSB(pbuf)
            Call B_GetUSBDeviceInfo(1, buf1, len1, buf2, len2)
            sw = 1
            If sw Then
                ret = B_CreatePrn(12, buf2) ' open usb.
            Else
                ret = B_CreateUSBPort(1) ' must call B_GetUSBBufferLen() function fisrt.
            End If
            If 0 < ret Then
                strmsg = strmsg + "Open USB fail!"
            Else
                strmsg = strmsg + "Open USB:" + vbCrLf + "Device name: "
                strmsg = strmsg + Left(buf1, len1)
                strmsg = strmsg + vbCrLf + "Device path: "
                strmsg = strmsg + Left(buf2, len2)
                'sw = 2
                If 2 = sw Then
                    'Immediate Error Report.
                    pbuf = "^ee\r\n"
                    Call B_WriteData(1, pbuf, 5)   '^ee
                    ret = B_ReadData(pbuf, 4, 1000)
                End If
            End If
        Else
            Dim lpSA As SECURITY_ATTRIBUTES

            lpSA.nLength = Len(lpSA)
            ret = CreateDirectory(szSavePath, lpSA)
            ret = B_CreatePrn(0, szSaveFile) ' open file.
            strmsg = strmsg + "Open " + szSaveFile
            If 0 < ret Then
                strmsg = strmsg + " file fail!"
            Else
                strmsg = strmsg + " file succeed!"
            End If
        End If
        MsgBox (strmsg)
        If 0 < ret Then
            Exit Sub
        End If

        ' sample setting.
        Call B_Set_DebugDialog(1)
        Call B_Set_Originpoint(0, 0)
        Call B_Select_Option(2)
        Call B_Set_Darkness(8)
        Call B_Del_Pcx("*") ' delete all picture.
        Call B_WriteData(0, sznop2, Len(sznop2))
        Call B_WriteData(1, sznop1, Len(sznop1))
        ' When using standard label, and the printer is Intelli Print mode or Smart Print mode,
        ' When calling this function and giving the correct label information,
        ' the immediate print function will be enabled according to the label length setting.
        Call B_Set_LabelForSmartPrint(254 * 3, 30) ' label information: length= 3 * 25.4 mm, gap= 3 mm.
        
        'draw box.
        Call B_Draw_Box(20, 20, 4, 760, 560)
        Call B_Draw_Line(Asc("O"), 400, 20, 4, 540)

        'print text, true type text.
        Call B_Prn_Text(30, 40, 0, 2, 1, 1, Asc("N"), "PPLB Lib Example")
        Call B_Prn_Text_TrueType(30, 100, 30, "Arial", 1, 400, 0, 0, 0, "AA", "TrueType Font") 'save in printer.
        Call B_Prn_Text_TrueType_W(30, 160, 20, 20, "Times New Roman", 1, 400, 0, 0, 0, "AB", "TT_W: 多字元測試")
        
        Dim buff1(128) As Byte
        Dim buff2() As Byte
        Dim i As Long
        buff2 = StrConv("TT_Uni: 多字元測試", vbNarrow) 'Converts UNICODE(wide characters) to single-byte characters.
        For i = LBound(buff2) To UBound(buff2)
            buff1(i) = buff2(i)
        Next i
        buff1(26) = 0 'null.
        buff1(27) = 0
        Call B_Prn_Text_TrueType_Uni(30, 220, 30, "Times New Roman", 1, 400, 0, 0, 0, "AC", buff1(0), 1) 'UTF-16
        
        buff1(0) = 255 'UTF-16.
        buff1(1) = 254
        buff2 = StrConv("TT_UniB: 多字元測試", vbNarrow) 'Converts UNICODE(wide characters) to single-byte characters.
        For i = LBound(buff2) To UBound(buff2)
            buff1(i + 2) = buff2(i)
        Next i
        buff1(30) = 0 'null.
        buff1(31) = 0
        Call B_Prn_Text_TrueType_UniB(30, 280, 30, "Times New Roman", 1, 400, 0, 0, 0, "AD", buff1(0), 0) 'Byte Order Mark.

        'barcode.
        Call B_Prn_Barcode(420, 100, 0, "3", 2, 3, 40, Asc("B"), "1234<+1>") 'have a counter.
        Call B_Bar2d_QR(420, 200, 1, 3, Asc("M"), Asc("A"), 0, 0, 0, "QR CODE")

        'picture.
        Call B_Get_Graphic_ColorBMP(420, 280, "bb.bmp") ' Color bmp file.
        Call B_Get_Graphic_ColorBMPEx(420, 320, 200, 150, 2, "bb1", "bb.bmp") ' 180 angle.
        Dim himage As Long
        himage = LoadImage(0, "bb.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE)
        Call B_Get_Graphic_ColorBMP_HBitmap(630, 280, 250, 80, 1, "bb2", himage) ' 90 angle.
        If himage Then
            Call DeleteObject(himage)
        End If
        
        ' output.
        Call B_Print_Out(2) ' copy 2.

        ' close port.
        Call B_ClosePrn
End Sub
